package cn.easy.mortgage.utils;

import cn.easy.mortgage.domain.EstateEvalInfo;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;

public class ProjectUtil {

    public static BigDecimal calLoanAmount(EstateEvalInfo estateEvalInfo) {
        if (estateEvalInfo == null) {
            return BigDecimal.ZERO;
        }
        String propertyType = estateEvalInfo.getPropertyType();
        BigDecimal totalPrice = estateEvalInfo.getHouseTotalPrice();
        BigDecimal loanAmount;
        if (Constants.PROPERTY_TYPE_VILLA.equals(propertyType)) {
            loanAmount = totalPrice.multiply(BigDecimal.valueOf(0.5));
        }
        if (StringUtils.equalsAny(estateEvalInfo.getArea(), Constants.AREA_XIAOSHAN, Constants.AREA_YUHANG) && !propertyType.equals(Constants.PROPERTY_TYPE_VILLA)) {
            loanAmount = totalPrice.multiply(BigDecimal.valueOf(0.65));
        } else {
            loanAmount = totalPrice.multiply(BigDecimal.valueOf(0.7));
        }
        return loanAmount;
    }

    /**
     * 将数字打码
     *
     * @param num
     * @return
     */
    public static String getEncrypt(String num) {
        if (StringUtils.isBlank(num)) {
            return num;
        }
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < num.length(); i++) {
            if (Character.isDigit(num.charAt(i))) {
                buffer.append('*');
            } else {
                buffer.append(num.charAt(i));
            }
        }
        return buffer.toString();
    }

}
